<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<xn:title text="校内XNJS Ajax演示" />

<br>
<br>
<h2>
XNJS Ajax演示
</h2>
API文档见<a href="http://dev.xiaonei.com/wiki/Ajax">XNJS Ajax</a>

<hr>
<br>
<h4>
XNJS Ajax演示
</h4>
<br>
<br>
<br>

<script type="text/javascript">
<!--
  function app_ajax(type) {
    var ajax = new Ajax(type);
    ajax.ondone = function(data) {
      var ajax_display = document.getElementById('ajax_display');
      var json_display = document.getElementById('json_display');
      switch (type) {
        case Ajax.RAW:
          ajax_display.setTextValue(data);
          json_display.setTextValue('');
          break;
        case Ajax.JSON:
          var text =  'json.message = ' + data.message;
          text += '; json.type = ' + data.type;
          text += '; json.user_id = ' + data.user_id;
          ajax_display.setTextValue(text);
          json_display.setInnerXNML(data.xnml_user);
          break;
        case Ajax.XNML:
          ajax_display.setInnerXNML(data);
          json_display.setTextValue('');
          break;
      }
    }

    ajax.onerror = function(errobj) {
      var ajax_display = document.getElementById('ajax_display');
      var errmsg = '!!!<ERROR> error code: ' + errobj.error + '; error description: ' + errobj.error_message;
      ajax_display.setTextValue(errmsg);
    }

    var params = {
      type: type,
      user_id: Session.getUser(),
      param3: {in_param1: '333_111', in_param2: '333_222'}
    };
    ajax.post('http://www.leo.com/xnmlshell/demo/ajax_handler/ajax_all.jsp', params);
  }
//-->
</script>

<p>
<a href="#" onclick="app_ajax(Ajax.RAW); return false;">RAW</a>
</p>
<p>
<a href="#" onclick="app_ajax(Ajax.XNML); return false;">XNML</a>
</p>
<p>
<a href="#" onclick="app_ajax(Ajax.JSON); return false;">JSON</a>
</p>

<br />
<div id="ajax_display"></div>
<div id="json_display"></div>
